/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTROL;

import UTILITY.KetNoiDuLieu;
import java.sql.ResultSet;
import MODEL.khoa;
import MODEL.sinhvien;
import java.util.ArrayList;

/**
 *
 * @author CONGTHANH
 */
public class Khoa_Control {
    
     public static khoa tenkh(String sv){
        khoa k=new khoa();
        try{
            
            KetNoiDuLieu kn=new KetNoiDuLieu();
           // sinhvien l=new sinhvien();
            kn.open();
         //   String sql="select * from khoa where MaKH="+l.getMakhoa();
            String  sql="select * from khoa inner join sinhvien on khoa.makhoa=sinhvien.makhoa where khoa.makhoa='"+sv+"'";
            ResultSet rs=kn.executeQuery(sql);
            while(rs.next()){
                k.setMakhoa(rs.getString(1));
                k.setTenkhoa(rs.getString(2));
                k.setDienthoia(rs.getString(3));
                k.setWeb(rs.getString(4));  
            }
            kn.close();
            
        }catch(Exception ex)
        {
            System.out.println(ex.getMessage());
            
        }
        return k;
    }
     public static ArrayList<khoa> tenkhoacmb(){
        ArrayList<khoa> kq=new ArrayList<khoa>();
        try{
            String sql="select * from khoa";
            KetNoiDuLieu hp=new KetNoiDuLieu();
            hp.open();
            ResultSet rs=hp.executeQuery(sql);
            while(rs.next()){
                khoa k=new khoa();
                k.setMakhoa(rs.getString(1));
                k.setTenkhoa(rs.getString(2));
                
                kq.add(k);
            }
            hp.close();
            
        }catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        return kq;
     }
}
